package com.example.lanouhn.bantangapp.activities.fragments;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.lanouhn.bantangapp.R;
import com.example.lanouhn.bantangapp.activities.adapters.VpSelectedAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lanouhn on 16/7/22.
 */
public class Fragment_Msg extends Fragment {

    private VpSelectedAdapter  VPA;
    private ViewPager vp ;
    private TabLayout tab;
    private List<String> tabNames;
    //viewpager的数据集合
    private List<Fragment> fragments;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.msg_fragment,container,false);
        vp= (ViewPager) view.findViewById(R.id.vp);
        tab= (TabLayout) view.findViewById(R.id.tab);
        return view;
    }


    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        initData();//添加数据
        setDataToView();//绑定数据到视图

    }

    //数据集合
    private void initData() {
        //tab标签名称集合
        tabNames = new ArrayList();
        //Fragment集合
        fragments = new ArrayList();
        //tablayout数据集合
        tabNames.add(getResources().getString(R.string.notifination));
        tabNames.add(getResources().getString(R.string.likes));
        tabNames.add(getResources().getString(R.string.comment));

        // 添加页面
        fragments.add(new Fragment_Msg_Notifination());
        fragments.add(new Fragment_Msg_Likes());
        fragments.add(new Fragment_Msg_Comment());

    }
    //绑定数据
    private void setDataToView() {
        VPA = new VpSelectedAdapter(getChildFragmentManager(),tabNames,fragments);
        //设置适配器
        vp.setAdapter(VPA);
        //tabLayout和ViewPager绑定
        tab.setupWithViewPager(vp);
    }

}
